{% extends 'base.html' %}
{% block title %} 我的博客 {% endblock %}
{% block mycss %}
    <style>
        .box {
            width: 100%;
            border-bottom: dashed 1px lightblue;
            margin-bottom: 10px;
            padding: 10px 20px;
        }
    </style>
{% endblock %}
{% block bodycontent %}
    <div class="container">
        {% if myarticles %}
            {% for article in myarticles %}
                <div class="box">
                    {#get请求的方式获取文章的id号#}
                    {#  ?变量名 = 文章id号 使用超链接获取文章的id号 (get请求路径传参方式)#}
                    <h3><a href="{{ url_for('blog.detail') }}?articleid={{ article.aid }}" style="color: deepskyblue">{{ article.title }}</a></h3>
                    <p>{{ article.thumb_content }}</p>
                    <div>
                        {#user就是设置的反向联系#}

                        <span>发布时间：{{ article.pubdate }}</span>
                        &nbsp;&nbsp;&nbsp;
                        <a href="#">
                        {#  浏览量#}
                            {#眼睛字体图标#}
                            <span class="glyphicon glyphicon-eye-open"></span>
                            <span>{{ article.looknum }}</span>
                        </a>
                        &nbsp;&nbsp;&nbsp;
{#                        该处有循环，所以比较麻烦#}
                        <a href="#" class="like" aid="{{ article.aid }}">
                        {#  点赞量#}
                            {# 赞 的手势字体图标#}
                            <span class="glyphicon glyphicon-thumbs-up"></span>
                            <span class="likes{{ article.aid }}">{{ article.likenum }}</span>
                        </a>
                        &nbsp;&nbsp;&nbsp;
                        <a class="del" href="{{ url_for('user.delarticle') }}?aid={{ article.aid }}" style="color: red">删除</a>
                    </div>
                </div>
            {% endfor %}
        {% else %}
            <h2 style="color: red">还没有发布过博客，赶快发布吧</h2>
        {% endif %}
    </div>
    {% block myjs %}
        <script>
            $(function () {
                    $.ajax({
                        url:"{{ url_for('user.mylikenum') }}",
                        data:{
                            aid:$('.like').attr('aid'),
                        },
                        type:'get',
                        success:function (data,status) {
                            if(status == 'success') {
                                var classnum = '.likes' + data.aid
                                $(classnum).text(data.likenum)
                            }
                        }
                    })

                $('.del').click(function () {
                    var res = confirm('是否确定要删除该篇博客？')
                    return res
                })
            })

        </script>
    {% endblock %}
{% endblock %}